﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Resources;
using System.Globalization;

namespace Reconciliation.Web.Users_Control
{
    public partial class Filters : System.Web.UI.UserControl
    {
        private string pagename;
        public string PageName
        {
            get
            {
                return pagename;
            }
            set { pagename = value; }
        }

        private DateTime startdate;
        public DateTime StartDate
        {
            get
            {
                return startdate;
            }
            set { startdate = value; }
        }

        private DateTime enddate;
        public DateTime EndDate
        {
            get
            {
                return enddate;
            }
            set { enddate = value; }
        }

        private int bankid;
        public int BankID
        {
            get
            {
                return bankid;
            }
            set { bankid = value; }
        }

        private string type;
        public string Type
        {
            get
            {
                return type;
            }
            set { type = value; }
        }

        private string ccp;
        public string CCP
        {
            get
            {
                return ccp;
            }
            set { ccp = value; }
        }

        private string amount_is;
        public string AmountIs
        {
            get
            {
                return amount_is;
            }
            set { amount_is = value; }
        }

        private float amount;
        public float Amount
        {
            get
            {
                return amount;
            }
            set { amount = value; }
        }
        

        public void LoadVariables()
        {
            if (!IsPostBack)
                FillBankList();
                        
            StartDate = Convert.ToDateTime(hddDate1.Value);
            EndDate = Convert.ToDateTime(hddDate2.Value);
            txtDateFromTo.Text = hddSelectedDate.Value;

            Type = ddType.SelectedValue.ToString();
            if (PageName == "Invoice")
            {
               
                lblTitle.Text =Convert.ToString( HttpContext.GetGlobalResourceObject("Lang", "Invoice_Status"));
                BankID = int.Parse(ddBank_Invoice.SelectedValue);
            }
            else
            {
                lblTitle.Text = Convert.ToString(HttpContext.GetGlobalResourceObject("Lang", "Reconciliation_Status"));
                BankID = int.Parse(ddBank_Status.SelectedValue);
                lnkFilter.Visible = false;
                CCP = ddCCP.SelectedValue.ToString();
                AmountIs = ddAmountFilter.SelectedValue.ToString();
                if (txtAmount.Text != "")
                    Amount = float.Parse(txtAmount.Text);

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {               
            lblTitle.Text = Resources.Lang.Invoice_Status.ToString();
            if (!IsPostBack)
            {
                if (PageName == "Invoice")
                {
                    pnlStausBlock.Visible = false;
                    pnlInvoiceBlock.Visible = true;
                }
                else
                {
                    pnlStausBlock.Visible = true;
                    pnlInvoiceBlock.Visible = false;
                }

                LoadVariables();              
            }
        }

        protected void imgApply_Click(object sender, ImageClickEventArgs e)
        {
            StartDate = Convert.ToDateTime(hddDate1.Value);
            EndDate = Convert.ToDateTime(hddDate2.Value);
        }

        protected void ddType_SelectedIndexChanged(object sender, EventArgs e)
        {
            Type = ddType.SelectedValue.ToString();
        }
        protected void ddBank_Status_SelectedIndexChanged(object sender, EventArgs e)
        {
            BankID = int.Parse(ddBank_Status.SelectedValue);
        }

        protected void lnkFilter_Click(object sender, EventArgs e)
        {
            if (lnkFilter.Text == Resources.Lang.Close.ToString())
            {
                //pnlFilter.Visible = false;
                lnkFilter.Text = Resources.Lang.Filter.ToString();
            }
            else
            {
                //pnlFilter.Visible = true;
                lnkFilter.Text = Resources.Lang.Close.ToString();
            }
        }
      
        private void FillBankList()
        {
            List<Reconciliation.Domain.Bank> bankList = new List<Reconciliation.Domain.Bank>();
            bankList = Services.ListOfValues.GetBankList();

            List <Reconciliation.Domain.Cpc> CpcList=new List<Reconciliation.Domain.Cpc>();
            CpcList = Services.ListOfValues.GetCpcList();
            ddBank_Invoice.DataSource = bankList;
            ddBank_Invoice.DataTextField = "BankCode";
            ddBank_Invoice.DataValueField = "BankID";
            ddBank_Invoice.DataBind();

            ddBank_Status.DataSource = bankList;
            ddBank_Status.DataTextField = "BankCode";
            ddBank_Status.DataValueField = "BankID";
            ddBank_Status.DataBind();

            ddCCP.DataSource = CpcList;
            ddCCP.DataTextField = "CpcCode";
                ddCCP.DataValueField="CpcID";
                ddCCP.DataBind();
            /*            
            foreach (Reconciliation.Domain.Bank bl in bankList)
            {
                ddBank.Items.Add(bl.BankCode);
                ddBank.DataTextField = bl.BankCode;
                ddBank.DataValueField = bl.BankID.ToString();               
            }
            */

        }
        protected void ddBank_Invoice_SelectedIndexChanged(object sender, EventArgs e)
        {
            BankID = int.Parse(ddBank_Invoice.SelectedValue);
        }
        protected void ddCCP_SelectedIndexChanged(object sender, EventArgs e)
        {
            CCP = ddCCP.SelectedValue.ToString();
        }
        protected void ddAmountFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            AmountIs = ddAmountFilter.SelectedValue.ToString();
        }
}
}